package com.adou.d5;

import java.util.Random;
import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {


        int[]userNumbers = userSelectNumber();

        // 打印
        print(userNumbers);


        int[] lickNumbers = createLuckNumbers();
        print(lickNumbers);

//        int[]userNumbers = {14,24,12,5,18,22,9};
//        int[]lickNumbers = {14,24,12,6,19,23,9};
        judge(userNumbers, lickNumbers);

    }

    public static void judge(int[]userNumbers, int[]luckNumbers){
        // 分表用变量定义红球、蓝球命中数据量
        int redCount = 0;
        int blueCount = 0;

        // 红球命中数量
        for (int i = 0; i < userNumbers.length-1; i++) {
            for (int i1 = 0; i1 < luckNumbers.length-1; i1++) {
                if(userNumbers[i] == luckNumbers[i1]) {
                    redCount ++;
                    break;
                }
            }
        }

        // 蓝球命中数量
        if(userNumbers[6] == luckNumbers[6]) {
            blueCount = 1;
        }

        System.out.println("您命中红球数量是：" + redCount);
        System.out.println("您命中蓝球数量是：" + blueCount);


        if(redCount == 6 && blueCount ==1) {
            System.out.println("恭喜你，中奖1000万，开始享受人生啦！！！！");
        } else if(redCount == 6 && blueCount ==0) {
            System.out.println("恭喜你，中奖500万，开始稍微享受人生啦！！！！");
        } else if(redCount == 5 && blueCount ==1) {
            System.out.println("恭喜你，中奖5000，吃个海鲜大餐吧！！！！");
        } else if(redCount == 5 && blueCount ==0) {
            System.out.println("恭喜你，中3000，吃个小龙虾！！！！");
        } else if(redCount == 4 && blueCount ==1) {
            System.out.println("恭喜你，中小奖200元！！！！");
        } else if(redCount == 4 && blueCount ==0) {
            System.out.println("恭喜你，中小小奖10元！！！！");
        } else if(redCount == 3 && blueCount ==1) {
            System.out.println("恭喜你，中小小奖5元！！！！");
        } else {
            System.out.println("感谢您为福利彩票贡献2元");
        }
    }


    public  static int[] userSelectNumber(){
        int[] numbers = new int[7];
        Scanner sc = new Scanner(System.in);

        // 投注6个红球
        for (int i = 0; i < numbers.length-1; i++) {

            while(true) {
                System.out.print("请您输出第" + (i + 1) + "个红球号码，（1-33）不能重复:");
                int num = sc.nextInt();

                // 1-33之间
                if (num < 1 && num > 33) {
                    System.out.println("对不起，你输入有无，请重新数据");
                } else {
                    // 号码不能重复
                    if(exist(numbers, num)) {
                        System.out.println("对不起，你输入号码重复，请重新输入");
                    } else {
                        numbers[i] = num;
                        break;
                    }
                }
            }
        }

        while(true) {
            System.out.print("请输入最后一个蓝球号码：");
            int number = sc.nextInt();
            if(number < 1 && number >16) {
                System.out.println("您输入蓝球号码不对，请重新输入！");
            } else {
                numbers[6] = number;
                break;
            }
        }

        return numbers;
    }

    public  static boolean exist(int[] numbers, int num) {
        for (int i = 0; i < numbers.length; i++) {
            if(numbers[i] == num) {
                return true;
            }
        }
        return false;
    }

    // 随机号码
    public static int[] createLuckNumbers(){
        int[] numbers = new int[7];
        Random r = new Random();
        for (int i = 0; i < numbers.length-1; i++) {
            while(true) {
                int num  = r.nextInt(33) +1;
                if(!exist(numbers, num)) {
                    // 不重复
                    numbers[i] = num;
                    break;
                }
            }
        }

        numbers[6] = r.nextInt(16) +1 ;
        return numbers;
    }



    public static void print(int[]userNumbers) {
        for (int i = 0; i < userNumbers.length; i++) {
            if(i == userNumbers.length-1) {
                System.out.print(userNumbers[i]);
            } else {
                System.out.print(userNumbers[i] + ", ");
            }
        }
    }
}
